import type { MenuEntityReq, MenuTreeResult, ParentMenuResult, PermEntityReq } from "@/api/types";
import request from "@/utils/http";

/** 新增系统菜单 */
function createMenu(data: MenuEntityReq): Promise<Resp<string>> {
    return request({
        url: "/sys/menu/create",
        method: "post",
        data,
    });
}

/** 删除系统菜单 */
function removeMenu(id: string): Promise<Resp<null>> {
    return request({
        url: "/sys/menu/remove",
        method: "post",
        data: { id },
    });
}

/** 更新系统菜单 */
function updateMenu(data: MenuEntityReq): Promise<Resp<null>> {
    return request({
        url: "/sys/menu/update",
        method: "post",
        data,
    });
}

/** 获取菜单树 */
function listMenuTree(): Promise<Resp<MenuTreeResult[]>> {
    return request({
        url: "/sys/menu/listTree",
        method: "get",
    });
}

/** 查询父菜单 */
function listParentById(id: string): Promise<Resp<ParentMenuResult>> {
    return request({
        url: "/sys/menu/listParentById",
        method: "get",
        params: { id },
    });
}

/** 新增按钮权限 */
function createPermission(data: PermEntityReq): Promise<Resp<string>> {
    return request({
        url: "/sys/permission/create",
        method: "post",
        data,
    });
}

/** 删除按钮权限 */
function removePermission(id: string): Promise<Resp<null>> {
    return request({
        url: "/sys/permission/remove",
        method: "post",
        data: { id },
    });
}

/** 更新按钮权限 */
function updatePermission(data: PermEntityReq): Promise<Resp<null>> {
    return request({
        url: "/sys/permission/update",
        method: "post",
        data,
    });
}

/** 系统菜单相关接口 */
export const menuApi = {
    createMenu,
    removeMenu,
    updateMenu,
    listMenuTree,
    listParentById,
    createPermission,
    removePermission,
    updatePermission,
};
